package com.hose.commons;

import com.hose.util.HoseUtils;
import com.microsoft.playwright.Page;
import io.qameta.allure.Step;

public class FormUtil {

    @Step("表单：{inputName}={inputValue}")
    public static void inputFill(Page page, String inputName, String inputValue) {
        page.locator("//div[starts-with(@class,'ant-row') and descendant::*[text()='"+inputName+"']]//input").fill(inputValue);
    }

    @Step("表单：{inputName}={inputValue}")
    public static void textareaFill(Page page, String inputName, String inputValue) {
        page.locator("//div[starts-with(@class,'ant-row') and descendant::*[text()='"+inputName+"']]//textarea").fill(inputValue);
    }

    /** 示例：选择收款信息 **/
    @Step("表单：{elementName}={selectItem}")
    public static void selectedAndOpenDialogSearch(Page page, String elementName, String selectItem) {
        page.locator("//div[starts-with(@class,'ant-row') and descendant::*[text()='"+elementName+"']]//*[starts-with(@class,'fake_input')]").click();
        HoseUtils.wait(page);
        page.locator("(//*[@role='dialog']//input)[1]").fill(selectItem);
        HoseUtils.wait(page);
        page.locator("//*[@role='dialog']//*[@class='payer-item' and descendant::*[text()='"+selectItem+"']]").click();
        page.locator("//*[@role='dialog']//*[text()='确 认']").click();
        page.locator("//*[starts-with(@class,'fake_input') and descendant::*[contains(.,'"+selectItem+"')]]").waitFor();
    }

    /** 示例：选择费用类型 **/
    @Step("表单：{elementName}={selectItem}")
    public static void selectDownItem(Page page, String elementName, String selectItem) {
        page.locator("//div[starts-with(@class,'ant-row') and descendant::*[text()='"+elementName+"']]//*[@role='combobox']").click();
        page.locator("//*[starts-with(@class,'ant-select-dropdown')]//input").fill(selectItem);
        page.locator("//*[starts-with(@class,'ant-select-dropdown')]//input").press("Enter");
        page.locator("//li[@role='treeitem' and descendant::*[text()='"+selectItem+"']]").click();
        page.locator("//*[@class='field-feeType-fullPath' and text()='"+selectItem+"']").waitFor();
    }



}
